<?php
header('content-type:text/html;charset="utf-8"');
header('Access-Control-Allow-Origin:*');  
header('Access-Control-Allow-Methods:POST');  
header('Access-Control-Allow-Headers:x-requested-with,content-type');  

	// 连接数据库
	$db = mysql_connect("bdm291307286.my3w.com","bdm291307286","zn15890989005"); //这里的信息修改成你们自己的
	mysql_query("SET NAMES UTF8"); // 设置编码
	//如果连接数据库成功
	if($db){
		//选择数据库
		mysql_select_db("bdm291307286_db"); 
		if(isset($_POST['name']) || isset($_POST['submit'])){
			$username=@$_POST['name'];
		}else{
			exit('非法操作');
		}
		
		// 对表进行数据操作
		$query="select * from logininfo where loginName='$username'";
		$result=mysql_query($query);
	  	if(mysql_fetch_array($result)){//如果有值代表用户名存在。
			echo true;//有重复
		}else{
			echo false;//没有重复
		}
	  	if(isset($_POST['submit']) && $_POST['submit']=="注册"){
			$user=$_POST['username'];//username：表单的名称
			$qqOrWeixin = $_POST['qqOrWeixin'];
			$pass=md5($_POST['password']);
			$phone = $_POST['phone'];
			$email = $_POST['email'];
			$query="insert into logininfo(loginName,qqWeiNum,password,phone,qqemail) values('$user','$qqOrWeixin','$pass','$phone','$email')";
			mysql_query($query);
			setcookie('username',$user,time()+'3600*24*20','path=/','www.smilening.online');
			header('location:../html/login.html');
		}
	}else{
		echo "error";
	}
?>